package cn.tedu.wufl.xcw.adapter.controller;

import cn.tedu.wufl.xcw.adapter.response.ResultVO;
import cn.tedu.wufl.xcw.domain.bo.ContentBO;
import cn.tedu.wufl.xcw.domain.service.ContentService;
import cn.tedu.wufl.xcw.param.ContentParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(value = "content",tags = "内容管理")
@Slf4j
@RestController
@RequestMapping("/api/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    @ApiOperation("内容列表")
    @GetMapping("/selectAll")
    public ResultVO selectAll(){
        List<ContentBO> list = contentService.findAll();
        list.forEach(cbo-> System.out.println(cbo));
        return new ResultVO(list);
    }

    @ApiOperation("添加内容")
    @PostMapping("/insert")
    public ResultVO insertContent(@Validated @RequestBody ContentParam contentParam){
        contentService.addContent(contentParam);
        return new ResultVO("内容添加成功");

    }

    @ApiOperation("查询内容")
    @GetMapping("/findById")
    public ResultVO findById(Integer id){
        ContentBO content = contentService.queryById(id);
        return new ResultVO(content);
    }

    @ApiOperation("删除内容")
    @DeleteMapping("/deleteById")
    public ResultVO deleteById(Integer id){
        contentService.deleteById(id);
        return new ResultVO("删除成功");
    }

    @ApiOperation("修改内容")
    @PutMapping("/modify")
    public ResultVO updateContent(@Validated @RequestBody ContentParam content){
        contentService.modifyContent(content);
        return new ResultVO("修改成功");

    }

}
